package com.shoeshopping.action.zx;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.shoeshopping.entity.Goods;
import com.shoeshopping.formbean.zx.GoodsAdminForm;
import com.shoeshopping.service.zx.GoodsAdminService;
import com.shoeshopping.utils.zx.EasyUIResult;
import com.shoeshopping.utils.zx.JsonUtil;
import com.shoeshopping.utils.zx.Result;

@Controller("goodsAdminAction")
@Scope("prototype")
public class GoodsAdminActon extends ActionSupport implements ModelDriven<GoodsAdminForm>{

	GoodsAdminForm dataform = new GoodsAdminForm();
	
	Goods editGoods = null;

	@Resource
	GoodsAdminService goodsAdminService;
	
	public void list(){
		EasyUIResult result = null;
		try{
			result = goodsAdminService.list(dataform);
		} finally{
			JsonUtil.output(result);
		}
	} 
	
	public String add(){
		if(goodsAdminService.add(dataform)){
			return Result.SUCCESS;
		}
		return Result.ERROR;
	}
	
	public void delete(){
		goodsAdminService.delete(dataform);
		JsonUtil.output(Result.success());
	}
	
	public String edit(){
		editGoods = goodsAdminService.edit(dataform);
		if(editGoods != null){
			
			return Result.EDIT;
		}
		return Result.ERROR;
		
	}
	
	public String details(){
		editGoods = goodsAdminService.edit(dataform);
		if(editGoods != null){
			
			return Result.DETAILS;
		}
		return Result.ERROR;
	}
	
	@Override
	public GoodsAdminForm getModel() {
		return dataform;
	}
	
	public Goods getEditGoods() {
		return editGoods;
	}

	public void setEditGoods(Goods editGoods) {
		this.editGoods = editGoods;
	}

}
